<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<table class="display" id="print_area">
    <thead>
    <tr>
        <th>全选
            <input type="checkbox" id="form-updates6" value="1" onchange="checkAll(this,'check_salary_sta')"/></th>
        <th>员工工号</th>
        <th>姓名</th>
        <th>部门</th>
        <th>职务</th>
        <th>薪资项目</th>
        <th>合计</th>
    </tr>
    </thead>
    <tbody>
    <s:if test="#request.salaryStatisticses==null || #request.salaryStatisticses.size==0">
        <tr class="gradeX">
            <td colspan="7">暂无相关数据</td>
        </tr>
    </s:if>
    <s:else>

        <s:iterator value="#request.salaryStatisticses" status="sta" var="s">
            <s:set name="total" value="#s.id"></s:set>
            <s:if test="#sta.even">
                <tr class="gradeA">
            </s:if><s:else><tr class="gradeC"></s:else>
            <td><input type="checkbox" id="check_salary_sta" name="check_salary_sta" value="${s.id}"/></td>
            <td><a href="#employee/staff_view.xhtml?id=${s.employeeinfoWork.id}">${s.employeeinfoWork.workNo}</a></td>
            <td>${s.employeeinfoWork.baseId.name}</td>
            <td>${s.employeeinfoWork.organization.fullName}</td>
            <td>${s.employeeinfoWork.duty.dutyName}</td>
            <td><s:if test="#s.details==null || #s.details.size<=0">
                暂无
            </s:if>
                <s:else>
                    <s:iterator value="#s.details" var="detail">
                        <a class="button" href="javascript://">
                            <s:if test="#detail.structType.toString().equals('subsidy')"><span style="background:url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span></s:if>
                            <s:else><span style="background:url(${ctx}/images/img/delete.png)" class="icon">&nbsp;</span></s:else>${detail.schemeTitle}:${detail.schemeSalary}</a>
                    </s:iterator>
                </s:else>
            </td>
            <td>${s.actaulPaySalary}</td>
            </tr>
        </s:iterator>

    </s:else>
    </tbody>
</table>
<p>
	<%@ include file="/WEB-INF/pages/common/main_orgtab_pager.jsp"%>
</p>
<div class="grid_12">

    <br/>
    <div class="form-action clearfix">
        <p>

            <a href="javascript:void(0)" onclick="printList()" class="button"><span class="icon" style="background:url(${ctx}/images/img/printer.png)">&nbsp;</span>打印</a>
            <a href="javascript:void(0)" onclick="doReport()" class="button"><span class="icon" style="background:url(${ctx}/images/img/report_magnify.png)">&nbsp;</span>导出</a>
            <a href="javascript:void(0)" onclick="doReportDetail()" class="button"><span class="icon" style="background:url(${ctx}/images/img/report_magnify.png)">&nbsp;</span>导出详细</a>
        </p>
    </div>

</div>

<form method="post" name="export_form" />

<script type="text/javascript" src="${ctc}/js/jquery.printarea.js"></script>
<script type="text/javascript">
    //function searchClickEvent(){
    function buildData(){
        var year = $("#search_year").prev("span").html(); //2012年
        year = year.substr(0, year.length - 1); //2012
        var month = $("#search_month").prev("span").html(); //2月
        month = month.substr(0, month.length - 1); //2
        var lastOrgSelectionName = $("#org_sel_1").find("select:last").prev("span").html(); //最后一个部门select选中的项名
        var lastOrgSelectOptions = $("#org_sel_1").find("select:last").find("option"); //最后一个部门select的option列表
        //alert(lastOrgSelectOptions.length)
        //alert(lastOrgSelectionName)
        var selectionOrgId = 0;
        for(var i=0; i<lastOrgSelectOptions.length;i++){
            var opt = lastOrgSelectOptions[i];
            if($(opt).html() == lastOrgSelectionName){
                //alert("选中的部门ID:"+$(opt).val());
                selectionOrgId = $(opt).val();
                break;
            }
        }
        if($("#org_sel_1").find("select").length > 1){
            //如果最后一个部门没有选择，则查找其上一部门所有
            if(selectionOrgId == 0 || selectionOrgId == "-1"){
                var tempId = $("#org_sel_1").find("select:last").parent("div").attr("id"); //uniform-undefined-4
                selectionOrgId = tempId.substr("uniform-undefined-".length, tempId.length);
            }
        }


        var dutySelectionName = $("#duty_sel_1").prev("span").html();
        var dutySelectOptions = $("#duty_sel_1").find("option");
        var selectionDutyId = 0;
        for(var i=0; i<dutySelectOptions.length;i++){
            var opt = dutySelectOptions[i];
            if($(opt).html() == dutySelectionName){
                //alert("选中的职务ID:"+$(opt).val());
                selectionDutyId = $(opt).val();
                break;
            }
        }


        var data = {
            "year":year,
            "month":month,
            "selectionOrgId":selectionOrgId,
            "selectionDutyId":selectionDutyId,
            "organizationId":"${organizationId}"
        }
        return data;
    }

    function searchClickEvent(){
        var data = buildData();
        var url = "${ctx}/salary/salary_statistics_list.xhtml";
        $.ajax(url, {
            type: "POST",
            data: data,
            dataType:"html",
            cache:false,
            success:function(a) {
                $("#list_content_${organizationId}").html(a);
            },
            complete:function() {}
        });
    }
    
    function loadListContent(url, organizationId) {
    	var data = buildData();
        //refreshListContent(url, data);
    	$.ajax(url, {
            type: "POST",
            data: data,
            dataType:"html",
            cache:false,
            success:function(a) {
                $("#list_content_${organizationId}").html(a);
            },
            complete:function() {}
        });
    }

    //导出
    function doReport() {
        var p = $.param(buildData());
        document.export_form.action = "${ctx}/salary/statistics-report.xhtml?" + p;
        document.export_form.submit();
    }
    function doReportDetail(){
        var data = buildData();
        var url = "${ctx}/ajax/statistics-report.xhtml";
        $.ajax(url, {
            type: "POST",
            data: data,
            dataType:"json",
            cache:false,
            success:function(result) {
                if(result != null){
                    if(result.indexOf("success:") >= 0){
                        alert("导出成功，导出路径："+result.substr("success:".length, result.length));
                    }else if(result == "error:data_empty"){
                        alert("导出失败，没有数据")
                    }else if(result.indexOf("error:") >= 0){
                        alert("导出失败，失败原因："+result.substr("error:").length, result.length)
                    }
                }
            }
        });
    }

    function printList() {
        $("#print_area").printArea();
    }
</script>
            